<?php

namespace co2_OS;

class app
/*	app{}	*/
{
	protected
		$name,
		$base,
		$aptitude,
		$version
		;
	
	public function
	__construct
	(
		$app,
		$version=null
	)
	{
		$this->name=$app;
		$this->version=$version;
		
		try
		{
			$this->aptitude=current(aptitude::get('a',$this->name,$this->version));
		}
		catch(\co2\Exception $e)
		{
			throw new \co2\Exception('app not manifested');
		}
		
		$this->base=sysvar::get('apps').'/'.$app;
	}
	
	public function
	__get($key)
	
	{
	  switch($key)
	  
	  {
	     case'nutshell':
	     
	      die(var_dump('here'));
	     
	     break;
	  }
	}

	public function
	__toString
	()
	{
		return $this->name;
	}
	
	public function
	getAptitude()
	
	{
		return $this->aptitude;
	}

	public function
	getBase
	()

	{
		return $this->base;
	}

	public function
	isManifested
	()
	{
		return $this->manifested;
	}
	
	public function
	manifest()
	
	{
		$manifestf=sysvar::get('apps')."/$app/".version2path($version)."/manifest.xml";

		if(!file_exists($manifestf))
		return false;
	
		$manifest=new \DOMDocument;
	
		$manifest->load($manifestf);
	
		$man=new \stdClass;
	
		$man->dependencies=array();
	
		foreach($manifest->getElementsByTagName('dependency') as $dependency)
	
		{
			$d=new \stdClass;
		
			$d->type=$dependency->parentNode->nodeName;
		
			$d->name=$dependency->getAttribute('name');
		
			$d->version=$dependency->getAttribute('version');
		
			$man->dependencies[]=$d;
		}
	
		return $man;
	}
}
